package com.taiyuan.zfmvp.JUC.three;

import java.util.concurrent.CountDownLatch;

/**
 * @param
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption: countdownlatch练习 减少计数
 * @Date 2022/10/6
 * @return
 */
public class CountDownLatchDemo {
    //六个同学陆续离开教室
    public static void main(String[] args) throws Exception{

        //创建coutDowdlatch对象
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+" 号同学");
                    //计数-1
                    countDownLatch.countDown();
                }
            },String.valueOf(i)).start();
        }
        //在执行下一步操作的时候 阻塞
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"班长锁门走人");
    }

}
